package yunc.checkData.pojo;

import java.util.HashMap;
import java.util.List;

public class Data022 {
    private HashMap<String,Integer> data;

    public Data022() {
    }

    public Data022(HashMap<String, Integer> data) {
        this.data = data;
    }

    public Data022(TitleTide title, List<String> data) {
        HashMap<String,Integer> dataMap = new HashMap<>();
        for (int i = 0; i < data.size(); i++) {
            //解析基础数据
            HashMap<String, Integer> baseDatas = getDataListFromstr(title.getRecordTime(), data.get(i), 6, 5, 12);
            dataMap.putAll(baseDatas);
        }
        this.data = dataMap;
    }


    private String getDateFromIndex(String month,String str,int indexAt){

        String day = str.substring(2, 4);
        String hour = str.substring(4, 6);
        Integer minute = indexAt*5;
        String minuteStr = minute.toString();
        if (minuteStr.length()!=2) {
            minuteStr="0"+ minuteStr;
        }
        return month + "-" + day + " " + hour + ":" + minuteStr + ":00";
    }

    private HashMap<String,Integer> getDataListFromstr(String month, String str, int dataStartAt,int dataLength, int dataNum){
        HashMap<String,Integer> datas = new HashMap<>();

        for (int i = 0; i < dataNum; i++) {
            String data = str.substring(dataStartAt + (dataLength * i), dataStartAt + (dataLength * (i + 1)));
            String date = getDateFromIndex(month,str,i);
            datas.put(date,Integer.parseInt(data.replace(" ","")));
        }

        return datas;
    }


    public HashMap<String, Integer> getData() {
        return data;
    }

    public void setData(HashMap<String, Integer> data) {
        this.data = data;
    }

    public static void main(String[] args) {
        String str= "220100  88   90   90   90   92   90   90   87   87   82   81   77 ";
        System.out.println(new Data022().getDataListFromstr("2020-08",str,5,5,12));
    }
}
